package utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.core.UIComponent;

	/**
	 * 鼠标代理管理器
	 * wuxi create on 2012-9-13 15:35:37
	 * */
	public class MouseCurosrManager extends EventDispatcher
	{
		public function MouseCurosrManager()
		{
		}
		
		private static var _istance:MouseCurosrManager;
		
		public static function getInstance():MouseCurosrManager{
			if(!_istance){
				_istance = new MouseCurosrManager();
			}
			return _istance;
		}
		private var root:MapEditor = null;
		public function init(root:MapEditor):void{
			this.root = root;
			
			this.root.addEventListener(Event.ENTER_FRAME,render);
		}
		
		
		private var cursor:DisplayObject ;
		private var wapper:UIComponent = new UIComponent();
		public function showSelfCurosr(cursor:DisplayObject):void{
			if(!cursor){
				return;
			}
			var numC:int = this.wapper.numChildren;
			for(var i:int = 0; i < numC;i++){
				this.wapper.removeChildAt(0);
			}
			this.cursor = cursor;
			this.wapper.addChild(cursor);
			this.root.addElementAt(wapper,this.root.numChildren);
		}
		
		public function hideSelftCurosr():void{
			if(this.root.contains(wapper)){
				this.root.removeElement(wapper);
			}
			this.cursor = null;
		}
		
		
		private function render(event:Event):void{
			if(this.cursor && this.cursor.parent != null){
				this.cursor.x = this.root.mouseX;
				this.cursor.y = this.root.mouseY;
			}
		}
	}
}